# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=sandsifter
pkgver=2.8375e61
pkgrel=3
pkgdesc='The x86 processor fuzzer.'
groups=('blackarch' 'blackarch-fuzzer' 'blackarch-hardware')
arch=('x86_64' 'aarch64')
url='https://github.com/xoreaxeaxeax/sandsifter'
license=('custom:unknown')
depends=('python2' 'python2-argparse' 'capstone')
makedepends=('git' 'make' 'sed')
source=("git+https://github.com/xoreaxeaxeax/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

build () {
  cd $pkgname

  sed -i "s/\/usr\/bin\/python/\/usr\/bin\/python2/" *.py
  sed -i "s/INJECTOR = \".\/injector\"/INJECTOR = \"\/opt\/sandsifter\/injector\"/" sifter.py
  sed -i 's|-pthread|-pthread -static|' Makefile

  make
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/opt/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md

  cp -rft "$pkgdir/opt/$pkgname/" \
    disas/ gui/ injector mutator.py pyutil/ sifter.py summarize.py

  ln -sf "/opt/sandsifter/sifter.py" "$pkgdir/usr/bin/sifter"
  ln -sf "/opt/sandsifter/summarize.py" "$pkgdir/usr/bin/summarize"
}

